package com.example.boot1.conttoller;

import com.example.boot1.bean.BackDataBean;
import com.example.boot1.bean.VuePeiCuisineBean;
import com.example.boot1.service.VueCuisineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/vue")
public class StatisticsController {

    //目前业务种提供的简单数据样例
    @Autowired
    private VueCuisineService vueCuisineService;

    @GetMapping("/getSales")
    @ResponseBody
    public ResponseEntity<BackDataBean> getSales(HttpServletRequest request){
        ResponseEntity responseEntity = null;
        BackDataBean backDataBean = null;
        //查询销量逻辑
        try {
            List<VuePeiCuisineBean> vlist = vueCuisineService.findBySaleTop10();

            backDataBean = new BackDataBean();
            backDataBean.setCode(200);
            backDataBean.setMsg("保存成功！");
            backDataBean.setResult(vlist);

            responseEntity = ResponseEntity.status(HttpStatus.OK).body(backDataBean);
        }catch (Exception e) {

            backDataBean.setCode(202);
            backDataBean.setMsg("服务器错误！");
            backDataBean.setResult(null);
            responseEntity = ResponseEntity.status(HttpStatus.ACCEPTED).body(backDataBean);
            e.printStackTrace();
        }
        return responseEntity;
    }
}
